<?php
/**
 * Created by PhpStorm.
 * @description:
 * @time:
 * @Author: yfl
 * @QQ 554665488
 * Date: 2018-5-28
 * Time: 16:42
 */
$server = new swoole_server('1270.0.0.1', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
//固定包头跟包体协议
$server->set([
    'heartbeat_idle_time' => 6,
    'heartbeat_check_interval' => 3,
]);
$server->on('connect', function ($serv, $fd) {

});

$server->on('receive', function ($serv, $fd, $from_id, $data) {
    for ($i=0;$i<20;$i++){
        $serv->send($fd,pack('N',strlen($data).$data));
    }
});

$server->on('close', function ($serv, $fd) {
   echo $fd.'断开';
});
$server->start();